package cn.wen.yinxiu.member.controller;

import java.util.List;

import cn.wen.yinxiu.common.convention.result.Results;
import cn.wen.yinxiu.common.to.user.UserLoginTO;
import cn.wen.yinxiu.common.to.user.UserSimpleTO;
import cn.wen.yinxiu.common.to.user.UserTO;
import cn.wen.yinxiu.common.to.user.UserDataInfo;
import cn.wen.yinxiu.member.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yinxiu.member.service.UsersService;
import cn.wen.yinxiu.common.convention.result.ResultEntity;


/**
 * 用户表
 *
 * @ClassName: Users
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-21 22:19:26
 * @Description:
 */
@RestController
@RequestMapping("/web")
public class UsersController {

    @Autowired
    private UsersService usersService;

    /**
     * 获取用户详情信息
     * 注：只有本人才能获取调用
     * 使用Token作为Key存入到Redis存用户的简单信息比较是否为UserId
     *
     * @param userId
     * @return
     */
    @GetMapping("/api/user/detail/info")
    public ResultEntity<UserInfoVO> getUserInfo(@RequestParam("userId") Long userId) {
        UserInfoVO target = usersService.queryUserInfoById(userId);
        return Results.success(target);
    }

    /**
     * 获取当前正常的用户ID
     *
     * @return
     */
    @GetMapping("/api/user/id/list")
    public ResultEntity<List<UserDataInfo>> getUserIdList() {
        List<UserDataInfo> userIds = usersService.getUserIdList();
        return Results.success(userIds);
    }

    /**
     * 通过用户ID获取用户信息
     *
     * @return
     */
    @GetMapping("/api/user/info")
    ResultEntity<UserTO> getUserInfoById(@RequestParam("userId") Long userId) {
        UserTO res = usersService.getUserToInfoById(userId);
        return Results.success(res);
    }

    /**
     * 随机获取30个用户来实现基于用户的过滤协调算法
     *
     * @return
     */
    @GetMapping("/api/user/find/list")
    ResultEntity<List<Long>> getUserIdFind30() {
        List<Long> userIdList = usersService.getUserIdFind30();
        return Results.success(userIdList);
    }

    /**
     * 获取所有的关注对象
     *
     * @param userId
     * @return
     */
    @GetMapping("/api/user/follow/list")
    ResultEntity<List<Long>> getUserFollowList(@RequestParam("userId") Long userId) {
        List<Long> followList = usersService.queryUserFollowIdList(userId);
        return Results.success(followList);
    }

    /**
     * 获取当前正常的用户ID
     *
     * @return
     */
    @GetMapping("/api/user/info/phone")
    ResultEntity<UserLoginTO> getUserInfoByPhone(@RequestParam("phone") String phone) {
        UserLoginTO res = usersService.getUserInfoByPhone(phone);
        return Results.success(res);
    }

    /**
     * 获取当前正常的用户ID
     *
     * @return
     */
    @GetMapping("/api/user/info/account")
    ResultEntity<UserLoginTO> getUserInfoByAccount(@RequestParam("account") String account) {
        UserLoginTO res = usersService.getUserInfoByAccount(account);
        return Results.success(res);
    }

    /**
     * 通过用户ID获取用户基本想信息
     *
     * @return
     */
    @GetMapping("/api/user/simple/info")
    ResultEntity<UserSimpleTO> getUserSimpleInfoById(@RequestParam("userId") Long userId,
                                                     @RequestParam("friendId") Long friendId) {
        UserSimpleTO res = usersService.getUserSimpleInfoById(userId, friendId);
        return Results.success(res);
    }


}
